{% extends 'common/basic_list.html' %}

{% block list_title %}
    主机
{% endblock %}

{% block list_filter %}
    <div class="col-sm-6">
        <div class="input-group">
            <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-search"></i> 搜索</button>
            &nbsp;
            <a href="host_add/"
               class="btn btn-sm btn-success"> 新增</a>&nbsp;
            <a href="javascript:void(0)"
               onclick="scan_host()"
               class="btn btn-sm btn-success"> 扫描主机</a>
            &nbsp;
            <a href="javascript:void(0)"
               onclick="exportCsv()"
               class="btn btn-sm btn-success"> 导出列表</a>&nbsp;
            &nbsp;
            <a href="javascript:void(0)"
               onclick="deleteBatch()"
               class="btn btn-sm btn-danger"><i class="fa fa-trash"></i> 批量删除</a>
        </div>
    </div>
    <script>
        function exportCsv() {
            layer.load();
            let url = '/frontend/cmdb/host_list/host_export/?host=' +
                $('#id_host').val() + "&ip_filter=" + $('#id_ip_filter').val()
                + "&host_group=" + $('#id_host_group').val();
            window.location.href = url
            layer.closeAll('loading');
        }

        function scan_host() {
            layer.load();
            $.get('/frontend/cmdb/host_list/scan_host_job/', function () {
                location.reload()
                layer.closeAll('loading');
            })

        }
    </script>
{% endblock %}

{% block list_content %}
    <div class="ibox " style="display: none;" id="loading_div">
        <div class="spiner-example">
            <div class="sk-spinner sk-spinner-three-bounce">
                <div class="sk-bounce1"></div>
                <div class="sk-bounce2"></div>
                <div class="sk-bounce3"></div>
            </div>
        </div>
    </div>
    <table id="tb" class="table table-striped table-bordered table-hover dataTables-example dataTable">
        <thead>
        <tr>
            <th style="width:3%;"><input id="checkall" type="checkbox" class="i-checks"></th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="host_group" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    主机组
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="host_name" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    主机DNS名称
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="host" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    主机名
                </a>
            </th>
            <th style="width: 8%;">
                IP
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="idc" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    机房
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="os" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    系统内核
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="enable_ssh" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    使用SaltSSH
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="minion_status" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    Minion状态
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="create_time" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    创建时间
                </a>
            </th>
            <th style="width: 8%;">
                <a class="order-by-column" data-column="update_time" href="#">
                    <i class="fa fa-sort order-by-column_icon"></i>
                    更新时间
                </a>
            </th>
            <th style="width:15%;">操作</th>
        </tr>
        </thead>
        <tbody>
        {% for o in result_list %}
            <tr>
                <td>
                    <input type="checkbox" class="i-checks icheck" id="{{ o.id }}" name="input[]">
                </td>
                <td>{% ifequal o.host_group None %}
                    无
                {% else %}
                    {{ o.host_group }}
                {% endifequal %}
                </td>
                <td>{{ o.host_name }}</td>
                <td>{{ o.host }}</td>
                <td>{{ o.id|host_ip_filter }}</td>
                <td>{% ifequal o.idc None %}
                    无
                {% else %}
                    {{ o.idc }}
                {% endifequal %}</td>
                <td>{{ o.os }}</td>
                <td>{{ o.enable_ssh|enablessh_status_filter }}</td>
                <td>{{ o.minion_status|minion_status_filter }}</td>
                <td>{{ o.create_time }}</td>
                <td>{{ o.update_time }}</td>
                <td>
                    <a href="/frontend/cmdb/host_list/{{ o.id }}/host_edit/"
                       class="btn  btn-sm btn-info"><i class="fa fa-edit"></i>编辑</a>
                    <a href="javascript:void(0)"
                       onclick="deleteAction('{{ o.id }}')"
                       class="btn  btn-sm btn-danger"><i class="fa fa-trash"></i>删除</a>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}